package com.hosever.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.hosever.core.AbstractModel;
/**
 * 评论
 * @author Sever
 *
 */
@Entity
@Table(name="tbl_review")
public class Review extends AbstractModel {
	private static final long serialVersionUID = 1L;
	
	/**
	 * 所属文章FK
	 */
	//多对一，@JoinColumn与@column类似，指定映射的数据库字段
	@ManyToOne(targetEntity = Article.class)
	@JoinColumn(name="articleId",updatable=false)
	private Article article;
	/**
	 * 发表人FK
	 */
	@ManyToOne(targetEntity = User.class)
	@JoinColumn(name="userId",updatable=false) 
	private User user;
	/**
	 * 内容
	 */
	@Column(name="content", columnDefinition="TEXT", nullable=true)
	private String content;
	/**
	 * 评论/回复状态
	 * 0.无状态 1.被屏蔽
	 */
	private int Status;
	/**
	 * 所属评论FK
	 * --如果为空则属于评论
	 * --如果不为空则属于回复
	 */
	@ManyToOne(targetEntity = Review.class)
	@JoinColumn(name="parentRevId") 
	private Review parentRev; 
	/**
	 * 所回复人
	 */
	@ManyToOne(targetEntity = User.class)
	@JoinColumn(name="replyUserId",updatable=false) 
	private User replyUser;
	/**
	 * 回复
	 */
	@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
	@OrderBy("updateDate asc")
	private List<Review> replies = new ArrayList<Review>();
	/**
	 * 楼层
	 * --评论才有，回复没有。
	 */
	private Integer floor;
	
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public int getStatus() {
		return Status;
	}
	public void setStatus(int status) {
		Status = status;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public Article getArticle() {
		return article;
	}
	public void setArticle(Article article) {
		this.article = article;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public List<Review> getReplies() {
		return replies;
	}
	public void setReplies(List<Review> replies) {
		this.replies = replies;
	}
	public Review getParentRev() {
		return parentRev;
	}
	public void setParentRev(Review parentRev) {
		this.parentRev = parentRev;
	}
	public User getReplyUser() {
		return replyUser;
	}
	public void setReplyUser(User replyUser) {
		this.replyUser = replyUser;
	}
	public Integer getFloor() {
		return floor;
	}
	public void setFloor(Integer floor) {
		this.floor = floor;
	}
}
